Telegram Group & Telegram Channel
В Python можно создавать вызываемые объекты не только с помощью функций (def или lambda). Объект также считается вызываемым, если у него реализован магический метод call:


class truncater:
def __init__(self, length):
self._length = length

def __call__(self, s):
return s[0:self._length]


print(truncater(4)('abcdabcd')) # abcd


Поскольку декоратор по сути является функцией высшего порядка, его также можно реализовать в виде вызываемого объекта вместо функции:


class cached:
def __init__(self, func):
self._func = func
self._cache = {}

def __call__(self, arg):
if arg not in self._cache:
self._cache[arg] = self._func(arg)

return self._cache[arg]


@cached
def sqr(x):
return x * x


👉@BookPython



tg-me.com/BookPython/3680
Create:
Last Update:

В Python можно создавать вызываемые объекты не только с помощью функций (def или lambda). Объект также считается вызываемым, если у него реализован магический метод call:


class truncater:
def __init__(self, length):
self._length = length

def __call__(self, s):
return s[0:self._length]


print(truncater(4)('abcdabcd')) # abcd


Поскольку декоратор по сути является функцией высшего порядка, его также можно реализовать в виде вызываемого объекта вместо функции:


class cached:
def __init__(self, func):
self._func = func
self._cache = {}

def __call__(self, arg):
if arg not in self._cache:
self._cache[arg] = self._func(arg)

return self._cache[arg]


@cached
def sqr(x):
return x * x


👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/BookPython/3680

View MORE
Open in Telegram


Библиотека Python разработчика Telegram | DID YOU KNOW?

Date: |

China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.

How Does Telegram Make Money?

Telegram is a free app and runs on donations. According to a blog on the telegram: We believe in fast and secure messaging that is also 100% free. Pavel Durov, who shares our vision, supplied Telegram with a generous donation, so we have quite enough money for the time being. If Telegram runs out, we will introduce non-essential paid options to support the infrastructure and finance developer salaries. But making profits will never be an end-goal for Telegram.

Библиотека Python разработчика from us


Telegram Библиотека Python разработчика | Книги по питону
FROM USA